package net.loonggg.mvpdemo.controller;

import net.loonggg.mvpdemo.bean.User;
import net.loonggg.mvpdemo.presenter.UserInfoPresenter;
import net.loonggg.mvpdemo.view.IShowUserView;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.app.R;

public class MainActivity extends Activity implements IShowUserView {    
    private Button btn;    
    private TextView name_tv, age_tv, sex_tv;    
    private ProgressDialog pd = null;    
    
    private UserInfoPresenter userInfoPresenter;    
    @Override
    protected void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_presenter_activity);
        userInfoPresenter = new UserInfoPresenter(this);
        
        btn = (Button) findViewById(R.id.btn);
        name_tv = (TextView) findViewById(R.id.name_tv);
        age_tv = (TextView) findViewById(R.id.age_tv);
        sex_tv = (TextView) findViewById(R.id.sex_tv);
        pd = new ProgressDialog(this);
        pd.setMessage("please wait...");

        btn.setOnClickListener(new View.OnClickListener() {            @Override
            public void onClick(View v) {
                userInfoPresenter.getUserInfoToShow(1);
            }
        });
    }    
    
    @Override
    public void showLoading() {
        pd.show();
    }    
    
    @Override
    public void hideLoading() {
        pd.cancel();
    }   
    
    @Override
    public void toMainActivity(User user) {
        name_tv.setText(user.getName());
        age_tv.setText(user.getAge());
        sex_tv.setText(user.getSex());
    }    
    
    @Override
    public void showFailedError() {
        Toast.makeText(this, "获取信息有误", Toast.LENGTH_SHORT).show();
    }

}